Class 6 Exam  >  Class 6 Questions  >  What will be the output of the following C co... Start Learning for Free
What will be the output of the following C code?
    #include <stdio.h>
    int main()
    {
        int a = 10;
        double b = 5.6;
        int c;
        c = a + b;
        printf("%d", c);
    }
  • a)
    15
  • b)
    16
  • c)
    15.6
  • d)
    10
Correct answer is option 'A'. Can you explain this answer?
Most Upvoted Answer
What will be the output of the following C code? #include <stdio.h...
Understanding the Code
The provided C code snippet performs a simple arithmetic operation and prints the result. Let's break it down to understand the output.
Code Breakdown
- The code starts by including the standard input-output library with `#include `.
- Inside the `main` function, three variables are declared:
- `int a = 10;` (an integer)
- `double b = 5.6;` (a floating-point number)
- `int c;` (an integer that will store the result)
- The crucial line is `c = a + b;`. Here’s what happens:
- The integer `a` (10) is added to the double `b` (5.6).
- In C, when an integer is added to a floating-point number, the integer is implicitly converted to a double. Thus, the operation becomes: `10.0 (from a) + 5.6 = 15.6`.
Type Conversion
- The result `15.6` is a double, but `c` is declared as an integer.
- When assigning `15.6` to `c`, the decimal part is truncated (not rounded), so `c` will store only `15`.
Output of the Code
- The `printf` function is then called with the format specifier `%d`, which is used to print integers.
- Therefore, when `printf("%d", c);` executes, it prints the value of `c`, which is `15`.
Conclusion
- The final output of this code will indeed be `15`, making option 'A' the correct answer.
Free Test
Community Answer
What will be the output of the following C code? #include <stdio.h...
Understanding the Code
The given C code performs a simple arithmetic operation. Let's break it down step-by-step:
Variable Declaration
- An integer variable `a` is initialized to 10.
- A double variable `b` is initialized to 5.6.
- Another integer variable `c` is declared to store the result.
Arithmetic Operation
- The line `c = a + b;` adds the integer `a` and the double `b`.
Type Conversion
- In C, when an integer is added to a double, the integer is automatically converted to a double for the operation.
- So, the calculation becomes `10.0 + 5.6`, which equals `15.6`.
Storing the Result
- The result `15.6` is then assigned to the integer variable `c`.
- Since `c` is an integer, the decimal part is truncated, and only the integer part `15` is stored in `c`.
Output Statement
- The `printf("%d", c);` statement prints the value of `c`, which is now `15`.
Conclusion
- The output of the code will be `15`, which corresponds to option 'A'.
Thus, the correct answer is option 'A', as `15` is the result that gets printed after the arithmetic operation and type conversion.
Explore Courses for Class 6 exam
Question Description
What will be the output of the following C code? #include <stdio.h> int main() { int a = 10; double b = 5.6; int c; c = a + b; printf("%d", c); }a)15b)16c)15.6d)10Correct answer is option 'A'. Can you explain this answer? for Class 6 2025 is part of Class 6 preparation. The Question and answers have been prepared according to the Class 6 exam syllabus. Information about What will be the output of the following C code? #include <stdio.h> int main() { int a = 10; double b = 5.6; int c; c = a + b; printf("%d", c); }a)15b)16c)15.6d)10Correct answer is option 'A'. Can you explain this answer? covers all topics & solutions for Class 6 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for What will be the output of the following C code? #include <stdio.h> int main() { int a = 10; double b = 5.6; int c; c = a + b; printf("%d", c); }a)15b)16c)15.6d)10Correct answer is option 'A'. Can you explain this answer?.
Solutions for What will be the output of the following C code? #include <stdio.h> int main() { int a = 10; double b = 5.6; int c; c = a + b; printf("%d", c); }a)15b)16c)15.6d)10Correct answer is option 'A'. Can you explain this answer? in English & in Hindi are available as part of our courses for Class 6. Download more important topics, notes, lectures and mock test series for Class 6 Exam by signing up for free.
Here you can find the meaning of What will be the output of the following C code? #include <stdio.h> int main() { int a = 10; double b = 5.6; int c; c = a + b; printf("%d", c); }a)15b)16c)15.6d)10Correct answer is option 'A'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of What will be the output of the following C code? #include <stdio.h> int main() { int a = 10; double b = 5.6; int c; c = a + b; printf("%d", c); }a)15b)16c)15.6d)10Correct answer is option 'A'. Can you explain this answer?, a detailed solution for What will be the output of the following C code? #include <stdio.h> int main() { int a = 10; double b = 5.6; int c; c = a + b; printf("%d", c); }a)15b)16c)15.6d)10Correct answer is option 'A'. Can you explain this answer? has been provided alongside types of What will be the output of the following C code? #include <stdio.h> int main() { int a = 10; double b = 5.6; int c; c = a + b; printf("%d", c); }a)15b)16c)15.6d)10Correct answer is option 'A'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice What will be the output of the following C code? #include <stdio.h> int main() { int a = 10; double b = 5.6; int c; c = a + b; printf("%d", c); }a)15b)16c)15.6d)10Correct answer is option 'A'. Can you explain this answer? tests, examples and also practice Class 6 tests.
Explore Courses for Class 6 exam
Signup to solve all Doubts
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev